<?php

namespace Mlym\CodeGeneration\InitGeneration\Authorization;

use EasySwoole\Component\Singleton;
use EasySwoole\Http\Request;
use EasySwoole\HttpAnnotation\Utility\Scanner;
use FastRoute\RouteCollector;
use Mlym\CodeGeneration\ClassGeneration\ClassGeneration;
use Mlym\CodeGeneration\InitGeneration\Authorization\Method\Construct;
use Mlym\CodeGeneration\InitGeneration\Authorization\Method\Verify;
use Mlym\CodeGeneration\InitGeneration\Authorization\Method\VerifyToken;

class AuthorizationGeneration extends ClassGeneration
{
    function addClassData()
    {
        /**
         * 引入类
         */
        $this->getPhpNamespace()->addUse(Singleton::class);
        $this->getPhpNamespace()->addUse(Request::class);
        $this->getPhpClass()->addTrait(Singleton::class);

        $this->getPhpClass()->addProperty('secretKey')->setPrivate()->addComment('@var string JWT secretKey');
        $this->getPhpClass()->addProperty('dataFields')->setPrivate()->addComment('@var array JWT Data存储的字段Key');
        $this->getPhpClass()->addProperty('ignoreAction')->setPrivate()->addComment('@var array 忽略的Action，不受登录和权限控制');

        $this->addGenerationMethod(new Construct($this));
        $this->addGenerationMethod(new Verify($this));
        $this->addGenerationMethod(new VerifyToken($this));
    }

    function addComment()
    {
        $this->phpClass->addComment(<<<BODY
* 授权校验类
* Class Authorization
* @package App\Logic
BODY
        );
    }
}